

package jetbrains.buildServer.server.rest.util;

import java.util.List;
import jetbrains.buildServer.server.rest.model.ItemsProviders;
import jetbrains.buildServer.server.rest.model.PagerData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ListBasedItemsRetriever<T> implements ItemsProviders.ItemsRetriever<T> {
  private final List<T> myItems;
  private final PagerData myPagerData;

  public ListBasedItemsRetriever(@NotNull List<T> items) {
    myItems = items;
    myPagerData = null;
  }

  public ListBasedItemsRetriever(@NotNull List<T> items, @Nullable PagerData pagerData) {
    myItems = items;
    myPagerData = pagerData;
  }

  @Nullable
  @Override
  public List<T> getItems() {
    return myItems;
  }

  @Override
  public Integer getCount() {
    return myItems.size();
  }

  @Override
  public boolean isCountCheap() {
    return true;
  }

  @Nullable
  @Override
  public PagerData getPagerData() {
    return myPagerData;
  }
}